{extend name='layouts/app'/}
{block name='content'}
<ul class="breadcrumb no-border no-radius b-b b-light pull-in">
    <li><a href="{:url('admin/index/index')}"><i class="fa fa-home"></i> 主页</a></li>
    <li class="active">会议管理</li>
</ul>
<div class="m-b-md">
    <h3 class="m-b-none">会议列表</h3>
</div>
<ul class="nav nav-tabs list-group">
    <li class="active"><a href="javascript:void(0);">会议列表</a></li>
    <li><a href="{:url('admin/meeting/create')}">新增会议</a></li>
</ul>
<section class="panel panel-default">
    <header class="panel-heading"> 数据列表：{$data->total()}个轮播</header>
    <div class="wrapper">
        <form  class="form-inline" role="form" action="{:url('admin/meeting/index')}" method="post">
            <div class="form-group">
                <div class="select">
                    <select name="status" class="input-sm form-control">
                        <option value="">- 状态 -</option>
                        {if condition="isset($_REQUEST.status) && $_REQUEST.status ==='0'"}
                        <option value="0" selected="selected">开启</option>
                        {else /}
                        <option value="0">开启</option>
                        {/if}
                        {if condition="isset($_REQUEST.status) && $_REQUEST.status ==1"}
                        <option value="1" selected="selected">关闭</option>
                        {else /}
                        <option value="1">关闭</option>
                        {/if}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="input-group">
                    <input type="text" class="input-sm form-control" name="keywords" value="{$_REQUEST.keywords ? $_REQUEST.keywords : ''}" placeholder="搜索条件标题">
                    <span class="input-group-btn">
                        <button type="submit" class="btn btn-sm btn-default">搜索</button>
                    </span>
                </div>
            </div>
        </form>
    </div>
    <div class="table-responsive">
        <table class="table table-striped table-hover b-t b-light text-sm">
            <thead>
            <tr>
                <th width="8%">排序</th>
                <th width="8%">编号</th>
                <th>标题</th>
                <th>副标题</th>
                <th>状态</th>
                <th width="100">操作</th>
            </tr>
            </thead>
            <tbody>
            {foreach name='data' item='vo'}
            <tr>
                <td class="v-middle"><input type="text" class="input-sm form-control text-center" onchange="sort(this, {$vo.id})" value="{$vo.sort}" placeholder="排序"></td>
                <td class="v-middle">{$vo.id}</td>
                <td class="v-middle">{$vo.name}</td>
                <td class="v-middle">{$vo.subtitle}</td>
                <td class="v-middle">{if condition="$vo.status neq 1"}<span style="color: green">开启</span>{else /}<span style="color: red">关闭</span>{/if}</td>
                <td class="v-middle">
                    <div class="btn-group">
                        <button data-toggle="dropdowns" class="btn btn-primary btn-xs dropdown-toggle">操作<span class="caret"></span></button>
                        <ul class="dropdown-menu dropdown-menu-right">
                            <li><a href="{:url('admin/meeting/edit', ['id'=>$vo.id])}">编辑</a></li>
                            <li class="divider"></li>
                            <li><a href="javascript:void(0);" onclick="destroy({$vo.id})">删除</a></li>
                        </ul>
                    </div>
                </td>
            </tr>
            {/foreach}
            </tbody>
        </table>
    </div>
    <footer class="panel-footer">
        <div class="row">
            <div class="col-sm-12 text-right text-center-xs">
                {$data->render()}
            </div>
        </div>
    </footer>
</section>
{/block}
{block name='script'}
<script type="text/javascript">
    /**
     * 异步更新排序
     * @param obj
     * @param id  会议ID
     */
    function sort(obj, id) {
        let sort = $(obj).val();
        $.post("{:url('admin/meeting/sort')}", {
            'id': id,
            'sort': sort
        }, function (data) {
            if (data.code === 1) {
                layer.msg(data.msg, {icon: 6});
                setTimeout('location.href = location.href', 2000);
            } else {
                layer.msg(data.msg, {icon: 5});
            }
        });
    }

    /**
     * 异步删除会议
     * @param id
     */
    function destroy(id) {
        layer.confirm('您确认要删除这个会议嘛?', {
            btn: ['确定', '取消']  //按钮
        }, function () {
            $.post("{:url('admin/meeting/destroy')}", {
                'id': id
            }, function (data) {
                if (data.code === 1) {
                    layer.msg(data.msg, {icon: 6});
                    setTimeout('location.href = location.href', 2000);
                } else {
                    layer.msg(data.msg, {icon: 5});
                }
            });
        }, function () {

        });
    }
</script>
{/block}